/*
 * Copyright 2006 - 2007 The MITRE Corporation. All rights reserved.
 * Written by Ayal Spitz
 *
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 2.1
 * (the "License"); you may not use this file except in compliance
 * with the License and the following two conditions:
 * 
 * The US Government will not be charged any license fee and/or royalties 
 * related to this software.
 * 
 * Neither name of The MITRE Corporation; nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * You may obtain a copy of the License at
 *
 *     http://www.gnu.org/copyleft/lesser.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

package org.mitre.streamingRSS;

import org.jivesoftware.smack.XMPPException;


/**
 * The Subscriber class is designed to simplify the process of participating in
 * an instantRSS session as an information subscriber. This class follows in the
 * footsteps of Ruby on Rails and puts convention over configuration, ie there
 * is an attempt to make smart defaults over long config files.
 * 
 * @author Ayal Spitz
 *
 */
public class Subscriber extends org.mitre.streamingRSS.xmpp.Subscriber{
	private String		userName = null, password = null;

// ### Class Constructor ######################################################
	/**
	 * This constructor allows the developer to set most the fields of 
	 * the constructor. The port is set to 5222
	 * 
	 * @param host		The XMPP host that this publisher should connect to
	 * @param username	The username of the XMPP user
	 * @param password	The password of the XMPP user
	 * 
	 * @see org.mitre.streamingRSS.xmpp.Common#Constructor(String,String,String)
	 */
	public Subscriber(String host,String username,String password){
		super(host);

		this.userName = username;
		this.password = password;
	}
	
	/**
	 * This constructor allows the developer to set all the fields of 
	 * the constructor.
	 * 
	 * @param host		The XMPP host that this publisher should connect to
	 * @param port		The XMPP port that this publisher should connect to
	 * @param username	The username of the XMPP user
	 * @param password	The password of the XMPP user
	 * 
	 * @see org.mitre.streamingRSS.xmpp.Common#Constructor(String,String,String)
	 */
	public Subscriber(String host,int port,String username,String password){
		super(host,port);

		this.userName = username;
		this.password = password;
	}

	/**
	 * This constructor allows the developer to setup a new instantRSS
	 * subscriber with the given username and password
	 * 
	 * @param username		The username of the publisher
	 * @param password		The password of the publisher
	 * 
	 * @see org.mitre.streamingRSS.xmpp.Subscriber#Constructor(String,String)
	 */
	public Subscriber(String username,String password){
		super();

		this.userName = username;
		this.password = password;
	}
	
	/**
	 * This constructor defaults to using the 'iRSS_Subscriber' as the username
	 * and 'InstantRSS' as the password
	 */
	public Subscriber(){ this("iRSS_Subscriber","InstantRSS"); }

// ### Class Methods ##########################################################
	public void connectAndLogin() throws XMPPException{ 
		connectAndLogin(this.userName,this.password, true);
	}
}
